package _9994FuWuDingWeiQo;

import java.util.ArrayList;
import java.util.List;

/**
 * @Cache: 缓存
 * @author: ZBoHang
 * @time: 2021/9/18 11:56
 */
public class Cache {
    private List<Service> services;

    public Cache() {
        services = new ArrayList<>();
    }

    public Service getService(String serviceName) {
        for (Service service : services) {
            if (service.getName().equalsIgnoreCase(serviceName)) {
                System.out.println("从缓存中拿到 --> " + serviceName);
                return service;
            }
        }
        return null;
    }

    public void addService(Service newService) {
        boolean exist = false;
        for (Service service : services) {
            if (service.getName().equalsIgnoreCase(newService.getName())) {
                exist = true;
            }
        }
        if (!exist) {
            services.add(newService);
        }
    }
}
